#!/bin/bash

ssh mason@brandgo.cn "cd ~/Code/upload/ &&  bash ~/Code/upload/backup.sh"
# 获取当前脚本的绝对路径

cd $PWD

# 确保 images 目录存在
if [[ ! -d "./images" ]]; then
  echo "Error: 'images' directory does not exist."
  exit 1
fi

# 上传 images 文件夹到远程服务器
REMOTE_DIR="mason@brandgo.cn:~/Code/upload/"
echo "Uploading images directory to remote server..."
echo "Current directory: $PWD"
scp -r ./images "$REMOTE_DIR"

# 执行远程脚本
ssh mason@brandgo.cn "cd ~/Code/upload/ && node ~/Code/upload/upload.js"

# 获取 urls.json 到本地文件夹
echo "Copying urls.json back to local directory..."
if ssh mason@brandgo.cn "test -f ~/Code/upload/urls.json"; then
  scp "mason@brandgo.cn:~/Code/upload/urls.json" .
else
  echo "Error: remote urls.json does not exist."
  exit 1
fi

echo "All operations completed successfully."
